Documentation Index
Fetch the complete documentation index at: https://mintlify.com/LizandroCanul/back_sdo/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before installing the Yucatan Public Works API, ensure you have the following installed:Node.js
Version 18.x or higher recommended
PostgreSQL
Version 15.x with PostGIS 3.3+ extension
npm
Version 8.x or higher (comes with Node.js)
Docker
Optional but recommended for database setup
You can verify your Node.js version with
node --version and npm with npm --versionInstallation Steps
Install Dependencies
Install all required npm packages:This installs:
- NestJS framework and core modules
- TypeORM for database operations
- Passport.js for authentication
- Class-validator for request validation
- And other dependencies listed in package.json
Set Up the Database
Choose one of the following methods to set up PostgreSQL with PostGIS:This creates a PostgreSQL database with:
Option A: Using Docker Compose (Recommended)
The easiest way to get started is using the included Docker Compose configuration:- Image: postgis/postgis:15-3.3
- Port: 5432
- Database: obras_yucatan_db
- User: admin
- Password: password123
View docker-compose.yml
View docker-compose.yml
Option B: Manual PostgreSQL Installation
If you prefer to install PostgreSQL manually:- Install PostgreSQL 15 or higher
- Install the PostGIS extension
- Create the database:
Configure Environment Variables
Create a Edit the
.env file in the project root directory:.env file with your configuration:.env
Environment Variables Reference
| Variable | Description | Default |
|---|---|---|
DATABASE_HOST | PostgreSQL host address | localhost |
DATABASE_PORT | PostgreSQL port | 5432 |
DATABASE_USER | Database username | admin |
DATABASE_PASSWORD | Database password | password123 |
DATABASE_NAME | Database name | obras_yucatan_db |
Run Database Migrations
TypeORM will automatically synchronize the database schema when you start the application.The API uses TypeORM’s
synchronize option in development, which automatically creates tables based on your entities.In production, you should disable
synchronize and use proper migrations instead.Verify Installation
Test that the API is running correctly:Running Modes
The API supports different running modes for various environments:Development Mode
Runs with auto-reload on file changes:- Hot reload on code changes
- Detailed error messages
- Database synchronization enabled
- CORS enabled for all origins
Production Mode
Optimized build for production deployment:- Compiled JavaScript output
- Optimized performance
- Should disable database synchronization
- Configure CORS for specific origins
Debug Mode
Runs with Node.js debugger attached:Database Schema
The API automatically creates the following main tables:- obras: Public works projects
- obra_ubicaciones: Geographic locations for obras (PostGIS)
- users: System users with role-based access
- user_favorite_obras: User favorites relationship
- municipios: Municipalities
- dependencias: Government dependencies
- tipo_proyecto: Project type catalog
- estatus_obra: Work status catalog
- ejercicio_fiscal: Fiscal year catalog
- localidad: Locality catalog
Configuration Details
The API includes several important configurations:Global Validation Pipe
Fromsrc/main.ts:9-15:
CORS Configuration
Fromsrc/main.ts:18-23:
Troubleshooting
Database Connection Issues
Problem: Cannot connect to PostgreSQL Solutions:- Verify Docker container is running:
docker ps - Check database credentials in
.envmatch docker-compose.yml - Ensure PostgreSQL is listening on port 5432:
netstat -an | grep 5432 - Check firewall settings
PostGIS Extension Missing
Problem: Error about PostGIS geometry types Solutions:Port Already in Use
Problem: Port 3000 is already in use Solutions:- Kill the process using port 3000:
- Or change the port in
src/main.ts:25
Module Not Found Errors
Problem: Cannot find module errors after installation Solutions:TypeORM Synchronization Issues
Problem: Tables not being created Solutions:- Verify database exists and is accessible
- Check TypeORM configuration in your app module
- Manually create the database if needed
- Review entity files for syntax errors
Production Deployment
For production deployment, consider:Environment Variables
Use a secrets manager for sensitive credentials
Database Migrations
Disable
synchronize and use proper migrationsCORS Configuration
Restrict origins to your frontend domains
Process Manager
Use PM2 or similar for process management
Production Environment Variables
.env.production
Using PM2 for Production
Next Steps
Authentication Setup
Configure JWT tokens and create your first users
Database Schema
Understand the complete data model
API Reference
Explore all available API endpoints
Quick Start Guide
Make your first API requests